package com.hs.test_push2_server.controller;

import com.hs.test_push2_server.utils.GeTuiUtils;
import com.hs.test_push2_server.utils.TestM;
import jcifs.smb.SmbFile;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RequestMapping("/test")
@RestController
public class TestController {
    @Autowired
    GeTuiUtils geTuiUtils;

    @RequestMapping("/pull")
    public void pull(String fileName) throws IOException {
////        SysShareAdministration share = sysShareAdministrationService.selectSysShareAdministrationByShareType(1);   //配置的  读取地址信息
//        /* 读取共享文件夹，确认有那些文件 */
//        String url="smb://"+"10.130.5.156/Sample Results/";
//        /* 读取共享文件夹，确认有那些文件 */
//        int result =  getShareFile(url + fileName, "D:\\results\\results2021"
//                ,"10.130.5.156","Administrator","1");
//        System.out.println(result);
    }
    @RequestMapping("/down")
    public Object down(String fileName) {
        if(StringUtils.isEmpty(fileName)){

            return "请输入文件名";
        }
        SmbFile[] sharedFileList = TestM.getSharedFileList("smb://10.130.5.156/Sample Results/");
        for (SmbFile smbFile : sharedFileList) {
            System.out.println(smbFile.getName());
            TestM.downloadFileToFolder("smb://10.130.5.156/Sample Results/",
                    smbFile.getName(),"D://results/results2021/",smbFile.getName());
        }
        return "下载成功";

    }
    @RequestMapping("/down2")
    public Object down2(String fileName) {
        if(StringUtils.isEmpty(fileName)){

            return "请输入文件名";
        }
        SmbFile[] sharedFileList = TestM.getSharedFileList("smb://10.130.5.156/aa/");
        for (SmbFile smbFile : sharedFileList) {
            System.out.println(smbFile.getName());
            TestM.downloadFileToFolder("smb://10.130.5.156/aa/",
                    smbFile.getName(),"D://results/results2021/",smbFile.getName());
        }
        return "下载成功";

    }
//    /**
//     * 从共享文件夹下载文件到本地
//     * @param remoteUrl 共享文件路径
//     * @param localPath 本地保存路径
//     */
//    public static int getShareFile(String remoteUrl, String localPath,String ip,String username,String pwd) throws IOException {
//        UniAddress ua = UniAddress.getByName(ip);  /*ip，username，password这些值如果在正式项目中使用，全部应该通过配置文件来设置*///String ip = "192.168.0.188";
//        NtlmPasswordAuthentication auth = null; //有用户必须有密码
//        if (StringUtils.isNotEmpty(username)){
//            auth = new NtlmPasswordAuthentication(ip, username, pwd);
//        }else{
//            auth = new NtlmPasswordAuthentication(ip, null, null);
//        }
//        SmbSession.logon(ua, auth);//验证是否能够成功登录
//        SmbFile sf = new SmbFile(remoteUrl, auth);//创建Smb文件,地址一定要使用smb://
//        System.out.println("文件是否存在："+remoteUrl+"---"+sf.exists());//创建Smb文件,地址一定要使用smb://
//        if(sf.exists()){
//            IOUtils.copyLarge(sf.getInputStream(), new FileOutputStream(localPath+ "\\" + sf.getName()));
//            return 1;
//        }else{
//            return 2;
//        }
//    }

    @RequestMapping("/go")
    public void go(){
        geTuiUtils.pushMsg("a2a0b2ce57ebd7569354f4f296e128ea","你好","托马斯！");
    }
    @RequestMapping("/go1")
    public void go1(){
        geTuiUtils.pushMsg("d41eba26d05ba4d5f18c76b40ded851f","你好","托马111斯！");
    }
    @RequestMapping("/go2")
    public void go2(){
        geTuiUtils.pushMsg1("d41eba26d05ba4d5f18c76b40ded851f","你好","托马122211斯！");
    }

    @RequestMapping("/in")
    public void in(String cid,String deptId,String loginName){
        System.out.println(cid);
        System.out.println(deptId);
        System.out.println(loginName);
    }
}
